package com.zhuzg.oauth2.mapper;

import com.zhuzg.oauth2.domain.Client;
import com.zhuzg.oauth2.domain.MyGrantedAuthority;
import com.zhuzg.oauth2.domain.SysUser;
import com.zhuzg.oauth2.domain.Tser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from sys_user where username=#{value}")
    SysUser findByUserName(String username);

    @Select("select * from sys_user where mobile=#{value}")
    SysUser findByMobile(String mobile);

    /**
     * 根据用户id获取权限
     * @param id
     * @return
     */
    @Select("SELECT role_code as authority,role_name as name, role_description as `desc` from sys_user_role ur INNER JOIN sys_role r ON ur.role_id=r.id\n" +
            " WHERE ur.user_id = #{value} ")
    List<MyGrantedAuthority> findAuthritiesByUid(int id);


    @Insert("insert into tser(name,sex) value(#{name},#{sex})")
    void inert(Tser tser);
}
